home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
TurboTCP 1.0.1
/
MiniTelnet.source
/
CTelnetSettingsDLOG.cp
< prev
next >
Wrap
Text File
|
1993-12-10
|
9KB
|
436 lines
/*
** CTelnetSettingsDLOG.cp
**
** MiniTelnet application
** Telnet settings dialog director
**
** Copyright © 1993, FrostByte Design / Eric Scouten
**
*/
#include "CTelnetSettingsDLOG.h"
#ifndef TurboTCPHeaders
#include <Commands.h>
#include <TCLUtilities.h>
#include <TBUtilities.h>
#include <CApplication.h>
#include <CBartender.h>
#include <CDialog.h>
#include <CButton.h>
#include <CCheckBox.h>
#include <CEditText.h>
#include <cast.h>
#include "CDisposerChore.h"
#endif
#include <CDataFile.h>
#include <CPaneBorder.h>
#include <CRadioGroupPane.h>
#include "CMiniTelnetApp.h"
#include "CTelnetTerminal.h"
// item numbers in dialog box
#define itemOK 1
#define itemCancel 2
#define itemSave 3
#define itemHostName 4
#define itemBSPane 6
#define itemBS_BS 7
#define itemBS_DEL 8
#define itemGoAway 9
#define itemTitle 10
#define itemShowDebug 14
extern CApplication *gApplication;
extern CBartender *gBartender;
extern OSType gSignature;
// —— initialization ——
/*______________________________________________________________________
**
** ITelnetSettingsDLOG
**
** Initialize the settings dialog.
**
** aSupervisor (CDirectorOwner *): the supervisor for the dialog
**
*/
void CTelnetSettingsDLOG::ITelnetSettingsDLOG (CDirectorOwner *aSupervisor)
{
CButton *theButton;
CPane *thePane;
CPaneBorder *theBorder;
// set up the dialog box
CDLOGDirector::IDLOGDirector(DLOGSettings, aSupervisor);
// find important buttons & configure them
theButton = CheckedCast(itsWindow->FindViewByID(itemOK), CButton);
if (theButton) {
theButton->SetClickCmd(cmdOK);
((CDialog *) itsWindow)->SetDefaultButton(theButton);
}
theButton = CheckedCast(itsWindow->FindViewByID(itemCancel), CButton);
if (theButton)
theButton->SetClickCmd(cmdCancel);
theButton = CheckedCast(itsWindow->FindViewByID(itemSave), CButton);
if (theButton)
theButton->SetClickCmd(cmdSaveSettings);
// add a border for the dialog title
thePane = CheckedCast(itsWindow->FindViewByID(itemTitle), CPane);
if (thePane) {
theBorder = new(CPaneBorder);
if (theBorder) {
theBorder->IPaneBorder(kBorderBottom);
thePane->SetBorder(theBorder);
}
}
// get rid of that ugly border around the radio buttons
thePane = CheckedCast(itsWindow->FindViewByID(itemBSPane), CPane);
if (thePane) {
theBorder = thePane->GetBorder();
if (theBorder)
theBorder->SetBorderFlags(kBorderNone);
}
}
// —— settings record functions ——
/*______________________________________________________________________
**
** DefaultSettings
**
** Creates a new blank settings record and copies this to the dialog.
**
*/
void CTelnetSettingsDLOG::DefaultSettings (void)
{
r.signature = kTSRsignature;
r.settingsVersion = kTSRversion;
r.settingsMinVersion = 0;
r.hostName[0] = '\0';
BlockMove(&"UNKNOWN", &r.termEmulation, 8);
// r.backspaceChar = charBS;
r.backspaceChar = charDEL;
r.closeOnSessionEnd = FALSE;
r.showDebug = FALSE;
PutSettings();
}
/*______________________________________________________________________
**
** GrabSettings
**
** Get the settings from the dialog box fields and put them into the
** settings record.
**
*/
void CTelnetSettingsDLOG::GrabSettings (void)
{
CCheckBox *theCheckBox;
CEditText *theText;
CRadioGroupPane *theRadios;
short textSize;
short i;
char *p;
// blank out the settings record
p = (char *) &r;
for (i=0; i<sizeof(TelnetSettingsRec); i++)
*p++ = '\0';
// recreate signature, version info
r.signature = kTSRsignature;
r.settingsVersion = kTSRversion;
r.settingsMinVersion = 0;
// get host name
theText = CheckedCast(itsWindow->FindViewByID(itemHostName), CEditText);
if (theText) {
textSize = theText->GetLength();
textSize = textSize > 255 ? 255 : textSize;
BlockMove(*(theText->GetTextHandle()), &r.hostName, textSize);
r.hostName[textSize] = '\0';
}
// get terminal emulation
BlockMove(&"UNKNOWN", &r.termEmulation, 8);
// get backspace/del configuration
theRadios = CheckedCast(itsWindow->FindViewByID(itemBSPane), CRadioGroupPane);
if (theRadios)
r.backspaceChar = (theRadios->GetStationID() == itemBS_DEL ? charDEL : charBS);
// get window go away config
theCheckBox = CheckedCast(itsWindow->FindViewByID(itemGoAway), CCheckBox);
if (theCheckBox)
r.closeOnSessionEnd = theCheckBox->IsChecked();
// get show debug codes config
theCheckBox = CheckedCast(itsWindow->FindViewByID(itemShowDebug), CCheckBox);
if (theCheckBox)
r.showDebug = theCheckBox->IsChecked();
}
/*______________________________________________________________________
**
** PutSettings
**
** Copy the settings from the settings record to the dialog box fields.
**
*/
void CTelnetSettingsDLOG::PutSettings (void)
{
CCheckBox *theCheckBox;
CEditText *theText;
CPane *thePane;
CRadioGroupPane *theRadios;
// get host name
theText = CheckedCast(itsWindow->FindViewByID(itemHostName), CEditText);
if (theText)
theText->SetTextPtr((char *) &r.hostName, cstrlen(r.hostName));
// get backspace/del configuration
theRadios = CheckedCast(itsWindow->FindViewByID(itemBSPane), CRadioGroupPane);
if (theRadios)
theRadios->SetStationID((r.backspaceChar == charDEL) ? itemBS_DEL : itemBS_BS);
// get window go away config
theCheckBox = CheckedCast(itsWindow->FindViewByID(itemGoAway), CCheckBox);
if (theCheckBox)
theCheckBox->SetValue(r.closeOnSessionEnd);
// get show debug codes config
theCheckBox = CheckedCast(itsWindow->FindViewByID(itemShowDebug), CCheckBox);
if (theCheckBox)
theCheckBox->SetValue(r.showDebug);
// ignore other parms
// force redraw
thePane = CheckedCast(itsWindow, CPane);
if (thePane)
thePane->Refresh();
}
// —— dialog handling functions ——
/*______________________________________________________________________
**
** DoCommand
**
** Handle all commands that the dialog can understand.
**
** theCommand (long): the command number which was issued
**
*/
void CTelnetSettingsDLOG::DoCommand (long theCommand)
{
CButton *cancelBtn;
TelnetSettingsRec rTemp;
// what command did we get?
switch (theCommand) {
// OK, Cancel buttons: respond
case cmdOK:
if (EndDialog(cmdOK, TRUE)) {
GrabSettings();
BlockMove(&r, &rTemp, sizeof(TelnetSettingsRec));
if (CheckedCast(gApplication, CMiniTelnetApp))
((CMiniTelnetApp *) gApplication)->NewSession(&rTemp);
}
break;
case cmdCancel:
EndDialog(cmdCancel, FALSE);
break;
// Save Settings: do it
case cmdSave:
case cmdSaveAs:
case cmdSaveSettings:
GrabSettings();
DoSaveFile();
break;
// File->Close: cancel out of here
case cmdClose:
cancelBtn = ((CDialog *) itsWindow)->FindButton(cmdCancel);
if (cancelBtn)
cancelBtn->SimulateClick();
EndDialog(cmdCancel, FALSE);
break;
// not ours, send along the chain
default:
CDialogDirector::DoCommand(theCommand);
}
// if closing window, use a disposer chore
if ((dismissCmd != cmdNull) && (theCommand != cmdClose))
disposeViaUrgentChore(this);
}
/*______________________________________________________________________
**
** UpdateMenus
**
** Enable Telnet-specific commands.
**
*/
void CTelnetSettingsDLOG::UpdateMenus (void)
{
CDLOGDirector::UpdateMenus();
gBartender->EnableCmd(cmdSave);
gBartender->EnableCmd(cmdSaveAs);
}
// —— file interactions ——
/*______________________________________________________________________
**
** DoSaveFile
**
** Save a settings record to a file.
**
*/
void CTelnetSettingsDLOG::DoSaveFile (void)
{
Point corner; // top left corner of dialog box
Str255 origName; // default name for file
short nameLength; // length of default name
StringHandle prompt; // prompt string
Boolean wasLocked;
CDataFile *itsFile; // don’t keep the file around
SFReply macSFReply; // reply from Std File
// ask user for settings file name
FindDlogPosition('DLOG', putDlgID, &corner);
BlockMove(&r.hostName, &origName[1], 31);
nameLength = cstrlen(r.hostName);
origName[0] = (nameLength > 31 ? 31 : nameLength);
prompt = GetString(STR_SettingsPrompt);
FailNILRes(prompt);
MoveHHi((Handle) prompt);
HLock((Handle) prompt);
SFPPutFile(corner, *prompt, origName, NULL, &macSFReply, putDlgID, NULL);
ReleaseResource((Handle) prompt);
// create the file
TRY {
itsFile = new(CDataFile);
itsFile->IDataFile();
itsFile->SFSpecify(&macSFReply);
if (itsFile->ExistsOnDisk()) {
itsFile->Open(fsRdWrPerm);
itsFile->SetLength(0);
// TEMPORARY: need to reset file type
}
else {
itsFile->CreateNew(gSignature, kSettingsFileType);
itsFile->Open(fsRdWrPerm);
}
wasLocked = Lock(TRUE);
itsFile->WriteSome((Ptr) &r, sizeof(TelnetSettingsRec));
Lock(wasLocked);
itsFile->Close();
itsFile->Dispose();
}
CATCH {
ForgetObject(itsFile);
}
ENDTRY;
}